package com.whmskj.xjlhsc.jitapi;

import cn.dev33.satoken.annotation.SaIgnore;
import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.jitapi.dto.CurClsInfoDto;
import com.whmskj.xjlhsc.jitapi.mapper.DeviceMapper;
import com.whmskj.xjlhsc.jitapi.mapper.DictMapper;
import com.whmskj.xjlhsc.jitapi.mapper.EmpMapper;
import com.whmskj.xjlhsc.jitapi.mapper.InventoryMapper;
import com.whmskj.xjlhsc.utils.SCUtil;
import com.whmskj.xjlhsc.utils.SCUtil.ClassTimeRange;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: XJLHSC
 * @BelongsPackage: com.whmskj.xjlhsc.jit
 * @Author: lk
 * @CreateTime: 2025-06-10
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/jit")
@CrossOrigin("*")
@SaIgnore
public class JitController {


    @Autowired
    private DictMapper dictMapper;
    @Autowired
    private InventoryMapper inventoryMapper;
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private EmpMapper empMapper;

    /**
     * 查询极态字典
     *
     * @param code
     * @return
     */
    @GetMapping("/getDictByCode")
    public Result getDictByCode(@RequestParam String code) {
        return Result.success(dictMapper.getDictByCode(code));
    }

    /**
     * 查询极态字典-所有
     *
     * @return
     */
    @GetMapping("/getDictAll")
    public Result getDictAll() {
        return Result.success(dictMapper.getDictAll());
    }

    /**
     * 查询盘存月
     *
     * @param ym
     * @return
     */
    @GetMapping("/listInventoryByYm")
    public Result listInventoryByYm(@RequestParam String ym) {
        return Result.success(inventoryMapper.getInventoryRecordByYm(ym));
    }

    @GetMapping("/list-device")
    @Operation(description = "根据车间返回设备信息")
    public Result listDevice(@RequestParam String workshop) {
        return Result.success(deviceMapper.listDevice(workshop));
    }

    @GetMapping("/getEmpList")
    @Operation(description = "获取极态纱厂员工下拉列表")
    public Result getEmpList() {
        return Result.success(empMapper.getEmpList());
    }

    @GetMapping("/getProcessListByWorkshop")
    @Operation(description = "根据车间获取下面的工序")
    public Result getProcessListByWorkshop(Integer workshop) {
        return Result.success(dictMapper.getDictByFdb7(workshop));
    }

    @GetMapping("/getDeviceListByProcess")
    @Operation(description = "根据工序获取机台列表")
    public Result getDeviceListByProcess(Integer processId) {
        return Result.success(deviceMapper.getDeviceListByProcess(processId));
    }


    @GetMapping("/getCurrentClsInfo")
    @Operation(description = "获取当前班次")
    public Result getCurrentCls() {
        ClassTimeRange classTimeRange = SCUtil.getClassDateTimeRange();
        CurClsInfoDto curClsInfoDto = dictMapper.getCurrentCls(classTimeRange.getDateYmd(), classTimeRange.getScclass().getDescription());
        curClsInfoDto.setDateYmd(classTimeRange.getDateYmd());
        curClsInfoDto.setScclass(classTimeRange.getScclass().getDescription());
        return Result.success(curClsInfoDto);
    }

}
